﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataStandard.Tools
{
    internal class DataValuesConvert2Bytes
    {

        internal static byte[] Int16S_To_ByteS(int[] ints)
        {
            byte[] result = null;

            if (ints != null)
            { 
                for (int i = 0; i < ints.Length; i++)
                {
                    var temp = BitConverter.GetBytes((short)ints[i]);

                    result = MergeByteS(result, temp);
                }
            }

            return result;
        }

        internal static byte[] MergeByteS(byte[] bytes1, byte[] bytes2)
        {
            byte[] result = null;
            int length1 = 0;
            int length2 = 0;
            if (bytes1 != null)
            {
                length1 = bytes1.Length;
            }
            if (bytes2 != null)
            {
                length2 = bytes2.Length;
            }
            if (length1 + length2 > 0)
            {
                result = new byte[length1 + length2];
            }

            int index = 0;
            if (bytes1 != null)
            {
                for (int i = 0; i < bytes1.Length; i++)
                {
                    result[index] = bytes1[i];
                    index++;
                }
            }
            if (bytes2 != null)
            {
                for (int i = 0; i < bytes2.Length; i++)
                {
                    result[index] = bytes2[i];
                    index++;
                }
            }


            return result;
        }
    }
}
